package com.yunnuo.monitor.job.service.impl;

import com.yunnuo.monitor.job.dao.IJobLogDao;
import com.yunnuo.monitor.job.entity.MonJobLog;
import com.yunnuo.monitor.job.service.IJobLogService;
import com.yunnuo.system.comm.util.Empty;
import com.yunnuo.system.comm.util.page.TableDataInfo;
import com.yunnuo.system.users.entity.PageParams;
import org.hibernate.service.spi.ServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import javax.persistence.criteria.*;
import java.util.List;

/**
 * @author 魏洪福（15064000912@163.com）
 * @create 2018-09-26-9:39
 */
@Service
public class JobLogServiceImpl implements IJobLogService{

    @Autowired
    private IJobLogDao jobLogDao;

    @Override
    public void addVO(MonJobLog vo) throws ServiceException {

    }

    @Override
    public void updateVO(MonJobLog vo) throws ServiceException {

    }

    @Override
    public void delList(String[] ids) throws ServiceException {

    }

    @Override
    public void deleteVo(String id) throws ServiceException {

    }

    @Override
    public List<MonJobLog> findList() throws ServiceException {
        return null;
    }

    @Override
    public List<?> findList(MonJobLog vo, String other) throws ServiceException {
        return null;
    }

    @Override
    public MonJobLog findVO(String id) throws ServiceException {
        return null;
    }

    /**
     * 分页查询
     * @param pageParams
     * @param pageRequest
     * @return
     */
    @Override
    public TableDataInfo selecJobLogByPageParams(PageParams pageParams, PageRequest pageRequest) {
        TableDataInfo dataInfo=new TableDataInfo();
        Specification<MonJobLog> specification=new Specification<MonJobLog>() {
            @Override
            public Predicate toPredicate(Root<MonJobLog> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
                Path<String> namePath=root.get("jobName");
                String value=pageParams.getSearchValue();
                if(Empty.isNotEmpty(value)){
                    query.where(cb.like(namePath,"%"+value+"%"));
                }
                return null;
            }
        };
        Page<MonJobLog> jobLogs=jobLogDao.findAll(specification,pageRequest);
        dataInfo.setRows(jobLogs.getContent());
        dataInfo.setTotal(jobLogs.getTotalElements());
        return dataInfo;
    }
}
